package com.zyj.test.month1.day2;

/**
 * @author Yijia Zhang
 * @create 2024-04-23 22:45
 */
public class code0003 {
    //最长不重复的子串：滑动窗口
    public int lengthOfLongestSubstring(String s) {
        int[] map = new int[128];
        int r = 0;
        int l = 0;
        int len = s.length();
        int max = 0;
        while (r < len) {
            char rc = s.charAt(r);
            if (++map[rc] > 1) {
                while (map[rc] > 1) {
                    char lc = s.charAt(l);
                    map[lc]--;
                    l++;
                }
            }
            max = Math.max(max, r - l + 1);
            r++;
        }
        return max;
    }
}

